import Vue from 'vue'
import VueRouter from 'vue-router'
const Login = () => import(/*webpackChunkName: "login_register"*/ '@/components/Login.vue')
const Register = () => import(/*webpackChunkName: "login_register"*/ '@/components/register.vue')
const Bookshelf = () => import(/*webpackChunkName: "Bookshelf"*/ '@/components/Bookshelf.vue')

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    component: Login
  },
  {
    path: '/bookshelf',
    component: Bookshelf
  },
  {
    path: '/register',
    component: Register
  }
]

const router = new VueRouter({
  routes
})

// 路由导航守卫 未对接后台接口暂未开启 对接登录接口之后需开启
// router.beforeEach((to, from, next) => {
//   if(to.path=='/login'||to.path=='/register') return next()

//   const tokenStr = window.sessionStorage.getItem('token') // token字符串
//   if(!tokenStr) return next('/login')
//   next()
// })

export default router
